app.controller("signController",function($scope, $http,$routeParams){
       $scope.class_id=$routeParams.id;
       console.log($scope.class_id)
        $http({
            method: 'POST',
            url: '/OA/classclazz/sign',
            data:$.param({id:$scope.class_id}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (response) {
            console.log(response)               //总条数
            $scope.total = response.data.length;
            //反转函数转化abcd转dcba
            $scope.data = response.data;
            //选择显示的条数
            $scope.values = [{"limit":6}];
            //默认显示的条数
            $scope.selectedLimit=$scope.values[0];
            //默认显示当前页数
            $scope.currentPage = 1;
            if($scope.data != null){
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.currentPage-1),$scope.selectedLimit.limit*$scope.currentPage);
            }else{
                alert($scope.data);
            }
            $scope.page = {
                "limit":$scope.selectedLimit.limit,"pageSize":5,"pageNo":$scope.currentPage,"totalCount":$scope.total};
            // 2017 /7 /19
            // 定义一个空对象 , 用于更新和保存数据时临时存储
            $scope.prod = {};
            $scope.arrs=response.data;
            console.log($scope.arrs)
            // 定义一个单击签到按钮时触发的事件
            $scope.sign = function($index){
                if ($index>=0) {
                        $http({
                            method:"POST",
                            url:"/OA/signin/create",
                            data:$.param({class_id:$scope.class_id,student_id:$scope.arrs[$index+(($scope.page.pageNo-1)*$scope.page.limit)].id}),
                            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                        }).success(function (result) {
                                if (result.ok==true) {
                                    $(".operation").eq($index).css({color:"red"});
                                    window.location.reload()
                                }
                            }).error(function(result){
                            alert(result.error)
                        })
                };
            }
            // 取消签到
            $scope.signout = function($index){
                if ($index>=0) {
                    $scope.Json={class_id:$scope.class_id,student_id:$scope.arrs[$index+(($scope.page.pageNo-1)*$scope.page.limit)].id};
                    console.log($scope.Json)
                    $http({
                        method:"POST",
                        url:"/OA/signin/signout",
                        data:$.param($scope.Json),
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    }).success(function (result) {
                        if (result.ok==true) {
                            $(".operation").eq($index).css({color:"#222"});
                            window.location.reload()
                        }
                    }).error(function(result){
                        alert(result.error)
                    })
                };
            }
        })
        $scope.change = function(selectedLimit){
            $scope.page.limit = selectedLimit.limit;
            $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
        }
        $scope.pageChanged = function(){
            $scope.page.limit = $scope.selectedLimit.limit;
            $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
        }
        $scope.setPage = function (go) {
            $scope.length = Math.ceil($scope.total/$scope.selectedLimit.limit);
            console.log($scope.length);
            if(go > $scope.length){
                $scope.page.pageNo =  $scope.length;
                console.log($scope.length);

            }else{
                $scope.page.pageNo=go;
            }
            $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
        };
    });


